Florian Unger adds rptname, rptdigit options to tranform filter.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 17:23:31 +0000 (17:23 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 23 Aug 2013 17:23:31 +0000 (17:23 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4560 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/defs.h
gpsbabel/reference/transform-names.gpx [new file with mode: 0644]
gpsbabel/route.cc
gpsbabel/testo.d/transform.test
gpsbabel/transform.cc
gpsbabel/xmldoc/formats/options/transform-rptdigits.xml [new file with mode: 0644]
gpsbabel/xmldoc/formats/options/transform-rptname.xml [new file with mode: 0644]

index 80f2f1a4cdc6405236f027c667bf8e389c73024d..8609bf699b001acd18dab543497f03a9ca52f01d 100644 (file)
@@ -718,8 +718,10 @@ geocache_container gs_mkcont(const char* t);
 route_head* route_head_alloc(void);
 void route_add(waypoint*);
 void route_add_wpt(route_head* rte, waypoint* wpt);
+void route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits);
 void route_del_wpt(route_head* rte, waypoint* wpt);
 void track_add_wpt(route_head* rte, waypoint* wpt);
+void track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits);
 void track_del_wpt(route_head* rte, waypoint* wpt);
 void route_add_head(route_head* rte);
 void route_del_head(route_head* rte);
diff --git a/gpsbabel/reference/transform-names.gpx b/gpsbabel/reference/transform-names.gpx
new file mode 100644 (file)
index 0000000..be40ab9
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<gpx version="1.1" creator="GPSBabel - http://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/1">\r
+  <metadata>\r
+     <time>1970-01-01T00:00:00Z</time>\r
+    <bounds minlat="47.421095000" minlon="19.220695000" maxlat="47.421186000" maxlon="19.220939000"/>\r
+  </metadata>\r
+  <rte>\r
+    <rtept lat="47.421186000" lon="19.220939000">\r
+      <ele>152.000000</ele>\r
+      <time>2012-11-05T07:16:29Z</time>\r
+      <name>RPT01</name>\r
+      <hdop>2.000000</hdop>\r
+    </rtept>\r
+  </rte>\r
+  <rte>\r
+    <rtept lat="47.421095000" lon="19.220695000">\r
+      <ele>138.300000</ele>\r
+      <time>2012-11-05T07:17:37Z</time>\r
+      <name>RPT02</name>\r
+      <hdop>3.000000</hdop>\r
+    </rtept>\r
+  </rte>\r
+  <rte>\r
+    <name>Name Track</name>\r
+    <desc>Generated from track Name Track</desc>\r
+    <rtept lat="47.421186000" lon="19.220939000">\r
+      <ele>152.000000</ele>\r
+      <time>2012-11-05T07:16:29Z</time>\r
+      <name>Name Track03</name>\r
+      <hdop>2.000000</hdop>\r
+    </rtept>\r
+  </rte>\r
+  <rte>\r
+    <name>Name Track #2</name>\r
+    <desc>Generated from track Name Track #2</desc>\r
+    <rtept lat="47.421095000" lon="19.220695000">\r
+      <ele>138.300000</ele>\r
+      <time>2012-11-05T07:17:37Z</time>\r
+      <name>Name Track #204</name>\r
+      <hdop>3.000000</hdop>\r
+    </rtept>\r
+  </rte>\r
+</gpx>\r
index 1afb5d9e4df0038d0bacef34644f701969ba35ff..8a9e24714beddbd50bcf5468991cf88cdff134f8 100644 (file)
@@ -170,7 +170,7 @@ route_find_track_by_name(const char* name)
 }
 
 static void
-any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth)
+any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth, const char* namepart, int number_digits)
 {
   ENQUEUE_TAIL(&rte->waypoint_list, &wpt->Q);
   rte->rte_waypt_ct++; /* waypoints in this route */
@@ -178,16 +178,14 @@ any_route_add_wpt(route_head* rte, waypoint* wpt, int* ct, int synth)
     (*ct)++;
   }
   if (synth && !wpt->shortname) {
-    char tmpnam[10];
-    snprintf(tmpnam, sizeof(tmpnam), "RPT%03d",*ct);
-    wpt->shortname = xstrdup(tmpnam);
+    xasprintf(&wpt->shortname,"%s%0*d", namepart, number_digits, *ct);
     wpt->wpt_flags.shortname_is_synthetic = 1;
   }
   update_common_traits(wpt);
 }
 
 void
-route_add_wpt(route_head* rte, waypoint* wpt)
+route_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits)
 {
   // First point in a route is always a new segment.
   // This improves compatibility when reading from
@@ -196,11 +194,18 @@ route_add_wpt(route_head* rte, waypoint* wpt)
     wpt->wpt_flags.new_trkseg = 1;
   }
 
-  any_route_add_wpt(rte, wpt, &rte_waypts, 1);
+  any_route_add_wpt(rte, wpt, &rte_waypts, 1, namepart, number_digits);
 }
 
 void
-track_add_wpt(route_head* rte, waypoint* wpt)
+route_add_wpt(route_head* rte, waypoint* wpt)
+{
+  const char RPT[] = "RPT";
+  route_add_wpt_named(rte, wpt, RPT, 3);
+}
+
+void
+track_add_wpt_named(route_head* rte, waypoint* wpt, const char* namepart, int number_digits)
 {
   // First point in a track is always a new segment.
   // This improves compatibility when reading from
@@ -209,7 +214,14 @@ track_add_wpt(route_head* rte, waypoint* wpt)
     wpt->wpt_flags.new_trkseg = 1;
   }
 
-  any_route_add_wpt(rte, wpt, &trk_waypts, 0);
+  any_route_add_wpt(rte, wpt, &trk_waypts, 0, namepart, number_digits);
+}
+
+void
+track_add_wpt(route_head* rte, waypoint* wpt)
+{
+  const char RPT[] = "RPT";
+  track_add_wpt_named(rte, wpt, RPT, 3);
 }
 
 waypoint*
@@ -401,6 +413,8 @@ route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src)
     *dst_count = 0;
     *dst_wpt_count = 0;
   }
+
+  const char RPT[] = "RPT";
   QUEUE_FOR_EACH(src, elem, tmp) {
     route_head* rte_old = (route_head*)elem;
 
@@ -412,7 +426,7 @@ route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src)
     rte_new->rte_num = rte_old->rte_num;
     any_route_add_head(rte_new, *dst);
     QUEUE_FOR_EACH(&rte_old->waypoint_list, elem2, tmp2) {
-      any_route_add_wpt(rte_new, waypt_dupe((waypoint*)elem2), dst_wpt_count, 0);
+      any_route_add_wpt(rte_new, waypt_dupe((waypoint*)elem2), dst_wpt_count, 0, RPT, 3);
     }
     (*dst_count)++;
   }
index 77b8869818f41c2c8582e8addd6baa42ea08ab25..59f3f6ccb85024bc48c87c61108af98eab402ef9 100644 (file)
@@ -9,3 +9,6 @@ rm -f ${TMPDIR}/transform-wpt.gpx
 gpsbabel -i gpx -f ${REFERENCE}/expertgps.gpx -x nuketypes,waypoints,tracks -x transform,wpt=rte,del=y -o gpx,gpxver=1.1 -F ${TMPDIR}/transform-wpt.gpx
 compare ${REFERENCE}/transform-wpt.gpx ${TMPDIR}/transform-wpt.gpx 
 
+rm -f ${TMPDIR}/transform-names.gpx
+gpsbabel -t -i gpx -f ${REFERENCE}/track/seg2trk_test-seg.gpx -x nuketypes,routes,waypoints -x transform,rte=trk,del=y,rptname=y,rptdigits=2 -o gpx,gpxver=1.1 -F ${TMPDIR}/transform-names.gpx
+compare ${REFERENCE}/transform-names.gpx ${TMPDIR}/transform-names.gpx 
index 46bc0f329a8e1d484e718434a7bd4b10843d2d20..8167f5227591186b6425c7796351e07959a35aa9 100644 (file)
@@ -33,7 +33,13 @@ static char current_target;
 static route_head* current_trk;
 static route_head* current_rte;
 
-static char* opt_routes, *opt_tracks, *opt_waypts, *opt_delete;
+static char* opt_routes, *opt_tracks, *opt_waypts, *opt_delete, *rpt_name_digits, *opt_rpt_name;
+
+static char* current_namepart;
+
+static int name_digits, use_src_name;
+
+static char RPT[] = "RPT";
 
 static
 arglist_t transform_args[] = {
@@ -49,6 +55,14 @@ arglist_t transform_args[] = {
     "trk", &opt_tracks, "Transform waypoint(s) or route(s) into tracks(s) [W/R]", NULL,
     ARGTYPE_STRING, ARG_NOMINMAX
   },
+  {
+    "rptdigits", &rpt_name_digits, "Number of digits in generated names", NULL,
+    ARGTYPE_INT, "2", NULL
+  },
+  {
+    "rptname", &opt_rpt_name, "Use source name for route point names", "N",
+    ARGTYPE_BOOL, ARG_NOMINMAX
+  },
   {
     "del", &opt_delete, "Delete source data after transformation", "N",
     ARGTYPE_BOOL, ARG_NOMINMAX
@@ -81,10 +95,10 @@ transform_waypoints(void)
     wpt = waypt_dupe(wpt);
     switch (current_target) {
     case 'R':
-      route_add_wpt(rte, wpt);
+      route_add_wpt_named(rte, wpt, RPT, name_digits);
       break;
     case 'T':
-      track_add_wpt(rte, wpt);
+      track_add_wpt_named(rte, wpt, RPT, name_digits);
       break;
     }
   }
@@ -93,6 +107,10 @@ transform_waypoints(void)
 static void
 transform_rte_disp_hdr_cb(const route_head* rte)
 {
+  current_namepart = RPT;
+  if (rte->rte_name && *rte->rte_name && use_src_name) {
+    current_namepart = rte->rte_name;
+  }
   if (current_target == 'T') {
     current_trk = route_head_alloc();
     track_add_head(current_trk);
@@ -106,6 +124,10 @@ transform_rte_disp_hdr_cb(const route_head* rte)
 static void
 transform_trk_disp_hdr_cb(const route_head* trk)
 {
+  current_namepart = RPT;
+  if (trk->rte_name && *trk->rte_name && use_src_name) {
+    current_namepart = trk->rte_name;
+  }
   if (current_target == 'R') {
     current_rte = route_head_alloc();
     route_add_head(current_rte);
@@ -121,9 +143,9 @@ transform_any_disp_wpt_cb(const waypoint* wpt)
 {
   waypoint* temp = waypt_dupe(wpt);
   if (current_target == 'R') {
-    route_add_wpt(current_rte, temp);
+    route_add_wpt_named(current_rte, temp, current_namepart, name_digits);
   } else if (current_target == 'T') {
-    track_add_wpt(current_trk, temp);
+    track_add_wpt_named(current_trk, temp, current_namepart, name_digits);
   } else {
     waypt_add(temp);
   }
@@ -160,6 +182,13 @@ transform_process(void)
 {
   int delete_after = (opt_delete && (*opt_delete == '1')) ? 1 : 0;
 
+  use_src_name = (opt_rpt_name && (*opt_rpt_name == '1')) ? 1 : 0;
+
+  name_digits = 3;
+  if (rpt_name_digits && *rpt_name_digits) {
+    name_digits = atoi(rpt_name_digits);
+  }
+
   if (opt_waypts != NULL) {
     current_target = 'W';
     switch (toupper(*opt_waypts)) {
diff --git a/gpsbabel/xmldoc/formats/options/transform-rptdigits.xml b/gpsbabel/xmldoc/formats/options/transform-rptdigits.xml
new file mode 100644 (file)
index 0000000..b810e9a
--- /dev/null
@@ -0,0 +1,13 @@
+<para>\r
+This option lets you configure how many digits GPSBabel uses for numbering generated route point names.\r
+</para>\r
+<para>\r
+When GPSBabel creates route points during the transformation process these points are sequentially numbered and named "RPTxxx" where xxx represent the number. By default GPSBabel uses 3 digits for these numbers. Rationale: This way a large number of route points can be uniquely named while the generated names are limited to 6 characters. This limitation is imposed by specific GPS devices.\r
+</para>\r
+<para>\r
+Using this option GPSBabel can be configured to use less or more digits for the generated names. This option is best used in conjunction with the rptname option.\r
+</para>\r
+<example id="transform_rptdigits">\r
+<title>Convert a GPX track to a GPX route, deleting the original track, using 2 digits for the generated numbers.</title>\r
+<para><userinput>gpsbabel -i gpx -f track.gpx -x transform,wpt=trk,del,rptdigits=2 -o gpx -F route.gpx</userinput></para>\r
+</example>\r
diff --git a/gpsbabel/xmldoc/formats/options/transform-rptname.xml b/gpsbabel/xmldoc/formats/options/transform-rptname.xml
new file mode 100644 (file)
index 0000000..39a1c2f
--- /dev/null
@@ -0,0 +1,12 @@
+<para>\r
+With this option you can decide to let GPSBabel name generated route points according to their source track name.\r
+</para>\r
+<para>\r
+GPSBabel creates route points during the transformation process named "RPTxxx" where xxx is a numeric part.</para>\r
+<para>\r
+Using this option GPSBabel can be configured to replace the "RPT" part of the generated names by the name of the source track during the transformation process. This is especially usefull if several differently named tracks are contained in the source file which should each be transformed into routes.\r
+</para>\r
+<example id="transform_rptname">\r
+<title>Convert a GPX track to a GPX route, deleting the original track, naming the generated points like the original track name.</title>\r
+<para><userinput>gpsbabel -i gpx -f track.gpx -x transform,wpt=trk,del,rptname=y -o gpx -F route.gpx</userinput></para>\r
+</example>\r